//
//  CarOnSale_OnSaleCell.m
//  CarProjectTest
//
//  Created by lanou on 15/10/26.
//  Copyright © 2015年 完美的宇gogo. All rights reserved.
//

#import "CarOnSale_OnSaleCell.h"

#define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width
#define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height


@implementation CarOnSale_OnSaleCell



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        _backView = [[UIView alloc] initWithFrame:CGRectMake(10, 5, SCREEN_WIDTH - 20, 175)];
        _backView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_backView];
        
        CGFloat width = _backView.bounds.size.width;
        
        // 汽车图片大小 180 * 135
        _imageUrlView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 20, (width - 20) /3, (width - 20) * 135/ 3 / 180)];
//        _imageUrlView.image = [UIImage imageNamed:@"s6854_180"];
        [_backView addSubview:_imageUrlView];
        
        CGFloat imageUrlWidth = _imageUrlView.bounds.size.width;
        
        _carNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(imageUrlWidth + 20, 10, width - imageUrlWidth - 30, 60)];
        _carNameLabel.numberOfLines = 0;
        _carNameLabel.font = [UIFont systemFontOfSize:16];
//        _carNameLabel.text = @"呆是大家发送";
        [_backView addSubview:_carNameLabel];

        _discountIcon = [[UIImageView alloc]initWithFrame:CGRectMake(imageUrlWidth + 20, _carNameLabel.bounds.size.height + 15, 20, 20)];
//        _discountIcon.image = [UIImage imageNamed:@"iconfont-jiangjia"];
        [_backView addSubview:_discountIcon];
        
        _discountLabel = [[UILabel alloc]initWithFrame:CGRectMake(imageUrlWidth + 40, _carNameLabel.bounds.size.height + 10, 100, 30)];
        _discountLabel.font = [UIFont systemFontOfSize:14];
//        _discountLabel.text = @"直降5.4万";
        _discountLabel.textColor = [UIColor redColor];
        [_backView addSubview:_discountLabel];
        
        
        _tagLabel = [[UILabel alloc]initWithFrame:CGRectMake(width - 85, _carNameLabel.bounds.size.height + 10, 80, 30)];
        _tagLabel.textAlignment = NSTextAlignmentRight;
//        _tagLabel.text = @"有现车";
        [self setLable:_tagLabel];
        
        _currentPriceLabel = [[UILabel alloc]initWithFrame:CGRectMake(imageUrlWidth + 20, _discountLabel.frame.origin.y + 25, 100, 30)];
//        _currentPriceLabel.text = @"现价9.88万";
        [self setLable:_currentPriceLabel];
        
        _remainTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(width - 85, _discountLabel.frame.origin.y + 25, 80, 30)];
//        _remainTimeLabel.text = @"剩余10数";
        _remainTimeLabel.textAlignment = NSTextAlignmentRight;
        [self setLable:_remainTimeLabel];
        
        
        _buyCarButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _buyCarButton.frame = CGRectMake(5, _currentPriceLabel.frame.origin.y + 35, (width - 20) / 3, 30);
        [self setButton:_buyCarButton titleString:@"购车计算"];
        
        _callTelephoneButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _callTelephoneButton.frame = CGRectMake(10 + (width - 20) / 3, _currentPriceLabel.frame.origin.y + 35, (width - 20) / 3, 30);
        [self setButton:_callTelephoneButton titleString:@"拨打电话"];
        
        _inquiryPriceButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _inquiryPriceButton.frame = CGRectMake(15 + (width - 20) * 2 / 3, _currentPriceLabel.frame.origin.y + 35, (width - 20) / 3, 30);
        [_inquiryPriceButton setTitle:@"问最低价" forState:(UIControlStateNormal)];
        _inquiryPriceButton.titleLabel.font = [UIFont systemFontOfSize:14];
        _inquiryPriceButton.layer.cornerRadius = 5;
        _inquiryPriceButton.backgroundColor = [UIColor blueColor];
        [_backView addSubview:_inquiryPriceButton];
        
        
    }
    return self;
}

- (void)setLable:(UILabel *)label
{
    label.font = [UIFont systemFontOfSize:14];
    label.textColor = [UIColor grayColor];
    [_backView addSubview:label];
}


- (void)setButton:(UIButton *)button titleString:(NSString *)string
{
    [button setTitle:string forState:(UIControlStateNormal)];
    [button setTitleColor:[UIColor blueColor] forState:(UIControlStateNormal)];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    button.layer.cornerRadius = 5;
    button.layer.borderWidth = 0.5;
    button.layer.borderColor = [UIColor blueColor].CGColor;
    [_backView addSubview:button];
}





//// 字符串自适应高度
//+ (CGFloat)heightOfString:(NSString *)string
//{
//    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:18] forKey:NSFontAttributeName];
//    CGRect bound = [string boundingRectWithSize:CGSizeMake(200, 0) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dic context:nil];
//    return bound.size.height;
//}


+ (CGFloat)heightOfCell
{
    return 185;//(SCREEN_HEIGHT - 67)/3 + 10;
}





- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
